package com.tec.security.utils.security.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.tec.security.utils.other.LimitPage;
import com.tec.security.utils.response.Result;
import com.tec.security.utils.security.entity.UserInformation;
import com.tec.security.utils.security.service.UserInformationService;
import com.tec.security.utils.security.mapper.UserInformationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
* @author LL318
* @description 针对表【user_information】的数据库操作Service实现
* @createDate 2023-11-23 00:02:39
*/
@Service
public class UserInformationServiceImpl extends ServiceImpl<UserInformationMapper, UserInformation> implements UserInformationService{

    private final UserInformationMapper userInformationMapper;
    @Autowired
    public UserInformationServiceImpl(UserInformationMapper userInformationMapper) {
        this.userInformationMapper = userInformationMapper;
    }

    /**
     * @Author 陆林
     * @description 根据uuid查人员信息
     * @Date 2023-11-30
     */
    @Override
    public UserInformation selectInformationByUUID(String loginID) {
        QueryWrapper<UserInformation> userInformationQueryWrapper=new QueryWrapper<>();
        userInformationQueryWrapper.eq("uuid",loginID);
        return userInformationMapper.selectOne(userInformationQueryWrapper);
    }

    /**
     * @Author 陆林
     * @description 根据部门筛选条件查询人员信息
     * @Date 2023-11-29
     */
    @Override
    public Result selectPersonListByDepartment(String department, LimitPage limitPage) {
        Map<String,Object> result=new HashMap<>();
        QueryWrapper<UserInformation> userInformationQueryWrapper=new QueryWrapper<>();
        List<String> stringList= Arrays.asList(new String[]{"department", "name", "email", "profession", "sex", "grade", "identity","signuptime"});
        PageHelper.startPage(limitPage.getPage(), limitPage.getSize());
        userInformationQueryWrapper.select(stringList);
        if (!Objects.equals(department, "全部")) {
            userInformationQueryWrapper.eq("department", department);
        }
        List<UserInformation> list=userInformationMapper.selectList(userInformationQueryWrapper);
        result.put("total",list.size());
        result.put("list",list);
        return Result.success("请求成功",result);
    }

    /**
     * @Author 陆林
     * @description 检验邮箱是否存在
     * @Date 2023-11-30
     */
    @Override
    public boolean selectEmail(String email) {
        QueryWrapper<UserInformation> userInformationQueryWrapper=new QueryWrapper<>();
        userInformationQueryWrapper.eq("email",email);
        UserInformation userInformation=userInformationMapper.selectOne(userInformationQueryWrapper);
        return !Objects.isNull(userInformation);
    }

    /**
     * @Author 陆林
     * @description 更新头像
     * @Date 2023-11-30
     */
    @Override
    public boolean UpdateURl(String url,String uuid) {
        UpdateWrapper<UserInformation> userInformationQueryWrapper=new UpdateWrapper<>();
        userInformationQueryWrapper.eq("uuid",uuid).set("url",url);
        return userInformationMapper.update(null, userInformationQueryWrapper) > 0;
    }
}




